package com.project.ujob.controllers;

import java.io.FileInputStream;
import java.io.IOException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.project.ujob.utils.KeyUtil;
import com.project.ujob.utils.QiniuCloudUtil;
import com.project.ujob.utils.ResultVOUtil;
import com.project.ujob.vo.ResultVO;

@Controller
@RequestMapping("/ujob/fileupload")

public class FileUploadController {

	@Autowired
	private QiniuCloudUtil qiniuCloudUtil;

	/**
	 * 上传文件到七牛云存储
	 * 
	 * @param multipartFile
	 * @return
	 * @throws IOException
	 */
	@PostMapping("/qiniu")
	@ResponseBody
	public ResultVO uploadImgQiniu(@RequestParam("file") MultipartFile multipartFile) throws IOException {
		FileInputStream inputStream = (FileInputStream) multipartFile.getInputStream();
		String path = qiniuCloudUtil.upload(inputStream, KeyUtil.genUniqueKey()); // KeyUtil.genUniqueKey()生成图片的随机名
		return ResultVOUtil.success(path);

	}

}
